/**
 * Created by caiqyxyx on 2017/2/12.
 */
define(['durandal/app', 'durandal/composition', 'i18nCommon', 'http', 'jquery', 'knockout', 'BMap', 'bootbox','panel',
        'css!style/home/page-style2',
        'css!library/3rdparty/font-awesome/css/font-awesome.min'],
    function (app, composition, i18n, http, $, ko, baiduMap, Box,panal) {
        var law = new function () {
            var that = this;
            var mainMap;

            that.lawHomePage = ko.observable();
            that.lawEquipmentLocation = ko.observable();
            that.lawHumanTraj = ko.observable();
            that.lawCamera = ko.observable();

            composition.addBindingHandler('application-law', {
                init: function (dom) {
                    that._dom = dom;
                    that.bindUI();
                    that.renderUI();
                }
            });

            that.bindUI = function () {

//                var p = panal.getInstance('view/home/hello', {
//                    width: 516,
//                    height: 440,
//                    modal: true,
//                    title: '测试框'
//                }, {});

                $('.venus-menu').delegate('li','click',function(){
                    var target = $(this);
                    if(!target.hasClass("active")){
                        $('.venus-menu li').removeClass("active")
                        target.addClass("active");
                    }
                });


                //主页按钮点击
                that.lawHomePage = function () {

                };
                //定位按钮点击
                that.lawEquipmentLocation = function () {

                };
                //轨迹按钮点击
                that.lawHumanTraj =  function () {
                	var p = panal.getInstance('view/lawdynamic/lawinfo', {
                		width: 300,
						height: 150,
						bottom: '31px',
						right: '2px',
						title: "执法员信息",
                        modal: false,
                        resizable: false 
                    }, {map:mainMap});
                };
                //视频按钮点击
                that.lawCamera = function () {
                    
                };
            };

            that.renderUI = function () {
                // that.adjustUI();
                debugger
                that.initMap();

            };

            /**
             * 调整UI
             */
            that.adjustUI = function () {
                var clientWith = document.body.clientWidth;
                var navContainerWith = $('.law-nav-container')[0].clientWidth;
                $('.law-nav-container').css("margin", "0 " + (clientWith - navContainerWith) / 2 + "px")

            };

            /**
             * 初始化地图实例
             */
            that.initMap = function () {
                var map = new BMap.Map("application-map", {enableMapClick: false});
                var point = new BMap.Point(116.331398, 39.897445);
                map.centerAndZoom(point, 12);
                map.enableScrollWheelZoom();
                mainMap = map;


                var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
                var top_left_navigation = new BMap.NavigationControl();

                //  var geoc = new BMap.Geocoder();

                map.addControl(top_left_control);
                map.addControl(top_left_navigation);

                /*根据IP自动定位
                 var myCity = new BMap.LocalCity();
                 myCity.get(function (result) {
                 map.setCenter(result.name);
                 });*/
                /*地址解析定位*/
                // 创建地址解析器实例
                var myGeo = new BMap.Geocoder();
                // 将地址解析结果显示在地图上,并调整地图视野
                myGeo.getPoint("宁波市", function (_point) {
                    if (_point) {
                        map.centerAndZoom(_point, 12);
                        //map.addOverlay(new BMap.Marker(_point));
                    } else {
                        // alert("您选择地址没有解析到结果!");
                    }
                }, "宁波市");
            };
        };

        return law;

    });